package com.elcl.activity.interfaces;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.elcl.andbaselibrary.R;
import com.elcl.widget.comp.dialog.LoadingProgressDialog;
import com.elcl.widget.comp.toast.ToastUtils;
import com.elcl.storage.ApplicationCache;

/**
 * @author lichunlin 一般用在ctrl层中
 */
public abstract class BaseClassMethod implements BaseMethods {

    protected static final String B2T = "animation_btmToUp";
    protected static final String R2L = "animation_rightToLeft";

    @Override
    public void showToast(int resId) {
//		Toast.makeText(ApplicationCache.context, resId, Toast.LENGTH_SHORT)
//				.show();
        ToastUtils.showToast(resId);
    }

    @Override
    public void showToast(String content) {
//		Toast.makeText(ApplicationCache.context, content, Toast.LENGTH_SHORT)
//				.show();
        ToastUtils.showToast(content);
    }

    @Override
    public void showLongToast(String content) {
//		Toast.makeText(ApplicationCache.context, content, Toast.LENGTH_LONG)
//				.show();
        ToastUtils.showLongToast(content);
    }

    @Override
    public void showLongToast(int resId) {
//		Toast.makeText(ApplicationCache.context, resId, Toast.LENGTH_LONG)
//				.show();
        ToastUtils.showLongToast(resId);
    }

    @Override
    public void openActivty(Class<?> cls) {
        ApplicationCache.context.startActivity(new Intent(
                ApplicationCache.context, cls));
    }

    @Override
    public void openActivty(Class<?> cls, String mid) {
        Intent intent = new Intent(ApplicationCache.context, cls);
        intent.putExtra("mid", mid);
        ApplicationCache.context.startActivity(intent);
    }

    @Override
    public void openActivty(Class<?> cls, int[] animation) {

    }

    protected static LoadingProgressDialog dialog;

    @Override
    public void showProgressDialog(String... content) {
        if (null == dialog)
            dialog = new LoadingProgressDialog(ApplicationCache.context,
                    R.style.MyDialog);
        else{
            if (null == content || content.length == 0) {
                dialog.show();
                dialog.setContent("正在载入...");
            } else {
                dialog.show();
                dialog.setContent(content[0]);
            }
        }
    }

    @Override
    public void dismissProgressDialog() {
        try {
            if (null != dialog) {
                dialog.dismiss();
            }
        } catch (Exception e) {
            dialog = null;
            e.printStackTrace();
        }
    }

    @Override
    public void openActivtyByAnim(Class<?> cls, String animationType) {
        Intent intent = new Intent(ApplicationCache.context, cls);
        ApplicationCache.context.startActivity(intent);
        if (animationType.equals(B2T)) {
            ((Activity) ApplicationCache.context).overridePendingTransition(
                    R.anim.anim_btm2top, R.anim.anim_still);
        } else if (animationType.equals(R2L)) {
            ((Activity) ApplicationCache.context).overridePendingTransition(
                    R.anim.anim_right_in, R.anim.anim_still);
        }
    }

    @Override
    public void initBackBtn(int finishBtnId) {

    }

    @Override
    public void openActivty(Class<?> cls, Bundle bundle) {
        Intent intent = new Intent(ApplicationCache.context, cls);
        intent.putExtras(bundle);
        ApplicationCache.context.startActivity(intent);
    }
}
